package www.openteam.com.model.business.other;

import www.openteam.com.OTApplication;
import www.openteam.com.base.BaseModel;
import www.openteam.com.bean.CustomType;
import www.openteam.com.exception.ApiException;
import www.openteam.com.subscribe.CommonSubscriber;
import www.openteam.com.transformer.CommonTransformer;

/**
 * Created by hyd on 2016/10/15.
 */

public class SearchPMCInfoModel extends BaseModel {
    private boolean isQueryM = false;
    private boolean isQueryCP = false;
    private boolean isQueryCTI = false;
    private boolean isQueryS = false;

    public boolean queryMoneyTypeInfo(int pageSize, final SearchMOnListener searchMOnListener) {

        httpApiService.queryMoneyTypeInfo(pageSize)
                .compose(new CommonTransformer<CustomType>())
                .subscribe(new CommonSubscriber<CustomType>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(CustomType customType) {

                        isQueryM = true;
                        searchMOnListener.queryMSuccess(customType);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isQueryM = false;
                        searchMOnListener.queryMFail(e);
                    }
                });
        return isQueryM;
    }

    public boolean queryCopayTypeInfo(int pageSize, final SearchCPOnListener searchCPOnListener) {

        httpApiService.queryCopayTypeInfo(pageSize)
                .compose(new CommonTransformer<CustomType>())
                .subscribe(new CommonSubscriber<CustomType>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(CustomType customType) {

                        isQueryCP = true;
                        searchCPOnListener.queryCPSuccess(customType);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isQueryCP = false;
                        searchCPOnListener.queryCPFail(e);
                    }

                });

        return isQueryCP;


    }

    public boolean queryCocustomTypeInfo(int pageSize, final SearchCTIOnListener searchCTIOnListener) {
        httpApiService.queryCocustomTypeInfo(pageSize)
                .compose(new CommonTransformer<CustomType>())
                .subscribe(new CommonSubscriber<CustomType>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(CustomType customType) {

                        isQueryCTI = true;
                        searchCTIOnListener.queryCTISuccess(customType);

                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isQueryCTI = false;
                        searchCTIOnListener.queryCTIFail(e);
                    }
                });

        return isQueryCTI;
    }

    public boolean querySendTypeInfo(int pageSize, final SearchSOnListener searchSOnListener) {

        httpApiService.querySendTypeInfo(pageSize)
                .compose(new CommonTransformer<CustomType>())
                .subscribe(new CommonSubscriber<CustomType>(OTApplication.getmContext()) {
                    @Override
                    public void onNext(CustomType customType) {
                        isQueryS = true;
                        searchSOnListener.querySSuccess(customType);
                    }

                    @Override
                    protected void onError(ApiException e) {
                        super.onError(e);
                        isQueryS = false;
                        searchSOnListener.querySFail(e);
                    }
                });

        return isQueryS;


    }


    public interface SearchMOnListener {

        void queryMSuccess(CustomType customType);

        void queryMFail(Throwable throwable);

    }

    public interface SearchCPOnListener {

        void queryCPSuccess(CustomType customType);

        void queryCPFail(Throwable throwable);
    }

    public interface SearchCTIOnListener {

        void queryCTISuccess(CustomType customType);

        void queryCTIFail(Throwable throwable);
    }

    public interface SearchSOnListener {

        void querySSuccess(CustomType customType);

        void querySFail(Throwable throwable);
    }
}
